package com.sansecy.monitor.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

import com.sansecy.monitor.R;
import com.sansecy.monitor.see.LogBean;
import com.sansecy.monitor.utils.JsonUtils;

import java.util.Arrays;

public class ErrorDialog extends Dialog {

    public ErrorDialog(@NonNull Context context) {
        super(context);
    }

    private TextView tvErrorMsg;
    private TextView tvTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_error);
        tvErrorMsg = findViewById(R.id.tv_error_message);
        tvTitle = findViewById(R.id.tv_title);
        tvTitle.setMovementMethod(ScrollingMovementMethod.getInstance());
    }

    public void bindData(LogBean log) {
        tvTitle.setText(log.getMessage());
        StringBuilder builder = new StringBuilder();
        StackTraceElement[] trace = log.getException().getStackTrace();
        for (StackTraceElement stackTraceElement : trace) {
            builder.append(stackTraceElement).append("\n");
        }
        tvErrorMsg.setText(builder.toString());
    }
}
